import { reactive, onMounted, onBeforeUnmount, nextTick } from 'vue'

export default function() {
  const point = reactive({
    x: 0,
    y: 0
  })
  function savePoint(e) {
    // console.log(e.pageX, e.pageY)
    point.x = e.pageX
    point.y = e.pageY
  }
  async function newMessage(val) {
    // console.log(val)
    await nextTick()
    // console.log('update')
  }
  onMounted(() => {
    window.addEventListener('click', savePoint)
    newMessage('msg')
    // console.log('msg2')
  })
  onBeforeUnmount(() => {
    window.removeEventListener('click', savePoint)
  })

  return point
}